package demo;

import java.time.LocalDateTime;

import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.policy.WritePolicy;

public class TTLTest {
	
	
	
	public static void main(String[] args) throws Exception {

		IAerospikeClient client = AsClientUtil.getClient();
		System.out.println("client="+client);
		
		String namespace = "ns1";
		String dataSetName = "testset";
		String bin = "DATA";
		int num = 100;
		// 3 s 
		final int ttl = 3;
		WritePolicy policy = new WritePolicy();
		policy.expiration = ttl;
		
		System.out.println("namespace="+namespace);
		System.out.println("dataSetName="+dataSetName);
		System.out.println("bin="+bin);
		System.out.println("ttl="+ttl);

		System.out.println("num="+num);


		for(int i=0;i<num;i++) {
			String key = "key-"+i;
			String value = key+"-"+LocalDateTime.now();
			AsClientUtil.put(client, policy, namespace, dataSetName, key, bin, value);
		}
		
		System.out.println("TTLTest write done,"+LocalDateTime.now());
		
		// max ttl 
	

        for(int i=1;i<100;i++) {
        	System.out.println("year="+i);
        	final int maxttl = 3600*24*365*i;
        	policy.expiration = maxttl;
    		String key = "key-"+99;
    		String value = key+"-"+LocalDateTime.now();
    		AsClientUtil.put(client, policy, namespace, dataSetName, key, bin, value);
        }
		//  com.aerospike.client.AerospikeException: Error Code 4: Parameter error
        
		

		

	}
	
}
	